package com.example.myapplication.apter;

import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.myapplication.Config.Commom;
import com.example.myapplication.Config.TokenBean;
import com.example.myapplication.R;
import com.example.myapplication.ShuJu.MsvieinformationlistBean;
import com.example.myapplication.movie.MovieActivity;
import com.example.myapplication.movie.MoviedetailsActivity;

import java.util.List;

public class MsvieinformationlistApter extends RecyclerView.Adapter<MsvieinformationlistApter.MyHolder> {
    private Context context;
    private List<MsvieinformationlistBean.RowsBean> list;
    private Integer nums;
    private String TAG = "TAG";


    public MsvieinformationlistApter(Context context, List<MsvieinformationlistBean.RowsBean> list, Integer nums) {
        this.context = context;
        this.list = list;
        this.nums = nums;
    }


    @NonNull
    @Override
    public MsvieinformationlistApter.MyHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_newdislist, null);
        return new MsvieinformationlistApter.MyHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull MsvieinformationlistApter.MyHolder holder, int position) {
            //电影
            Glide.with(context).load(TokenBean.IP + list.get(position).getCover()).into(holder.newsdislist_img);
            holder.newsdislist_img.setScaleType(ImageView.ScaleType.FIT_XY);
            holder.newsdislist_title.setText(list.get(position).getName());
            holder.newsdislist_link.setText(list.get(position).getPlayDate());
            holder.newsdislist_dianzeng.setText(String.valueOf(list.get(position).getDuration()));
            //进入详情页
            holder.re_newsdislist.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(context, MoviedetailsActivity.class);
                    intent.putExtra(Commom.MSVIEIN_ID, String.valueOf(list.get(position).getId()));
                    Log.e(TAG, String.valueOf(list.get(position).getId()));
                    context.startActivity(intent);
                }
            });
    }

    @Override
    public int getItemCount() {
        return nums;
    }

    class MyHolder extends RecyclerView.ViewHolder {
        ImageView newsdislist_img;
        TextView newsdislist_title;
        TextView newsdislist_link;
        TextView newsdislist_dianzeng;
        RelativeLayout re_newsdislist;

        public MyHolder(@NonNull View itemView) {
            super(itemView);
            newsdislist_img = itemView.findViewById(R.id.newsdislist_img);
            newsdislist_title = itemView.findViewById(R.id.newsdislist_title);
            newsdislist_link = itemView.findViewById(R.id.newsdislist_link);
            newsdislist_dianzeng = itemView.findViewById(R.id.newsdislist_dianzeng);
            re_newsdislist = itemView.findViewById(R.id.re_newsdislist);

        }
    }
}



